﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;


namespace AfterCaveStory.Utils
{
    class txtToList
    {

        public static List<List<int>> loadTxt(String fileName)
        {
            List<List<int>> list = new List<List<int>>();

            //TODO ajeitar para a leitura ser feita no diretório correto

            //TODO a leitura deve ser feita no load, não quando apertar o enter

            string line = string.Empty;
            using (
                StreamReader sr = new StreamReader(fileName))
            {
                while ((line = sr.ReadLine()) != null)
                {

                    List<int> words = new List<int>();
                    string word;
                    string s = line.ToString();
                    s = s.ToUpper();
                    s = s.Trim(',', '.', '"', '-', ' ', ':', ';', '\n', '!', '?');
                    while (s.Length > 0)
                    {
                        if (s.Contains(' '))
                        {
                            word = s.Substring(0, s.IndexOf(" "));
                            s = s.Substring(s.IndexOf(" ") + 1);
                            s = s.Trim();
                        }
                        else
                        {
                            word = s;
                            s = "";
                        }
                        word = word.Trim(',', '.', '"', '-', ' ', ':', ';', '\n', '!', '?');
                        if (word.Length > 0)
                            words.Add(int.Parse(word));
                    }

                    list.Add(words);
          
                }

                return list;
            }

        }
    }
}
